<template>
  <div>
    <el-input v-model="user" placeholder="请输入用名"></el-input>
    <br />
    <br />
    <el-input
      placeholder="请输入密码"
      v-model="password"
      show-password
    ></el-input>
    <br />
    <br />
    <el-button type="success" @click="login()">登录</el-button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      user: "",
      password: ""
    };
  },
  methods: {
    login() {
      let that = this;
      this.$axios
        .post("/login", {
          user: that.user,
          password: that.password
        })
        .then(function(response) {
          if (response.data.code == 200) {
            localStorage.setItem("token", response.data.data);
            console.info(response.data);
            that.$router.push({
              path: "/shopList"
            });
          } else {
            console.info(response.data.message);
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    }
  }
};
</script>
